/**
 *  Copyright 2010 ShenYang voole Co. Ltd.
 *  All right reserved. 
 */
package cn.piaoyi.web.taglib;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.io.Writer;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.components.Component;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * 功能描述:分页
 *
 * 创建日期 May 25, 2010
 *
 * @author zhangbaochao
 *
 * @version 1.0
 *
 */
public class GoodsState extends Component {
	/**
	 * Logger for this class
	 */
	private static final Log logger = LogFactory.getLog(GoodsState.class);

	public GoodsState(ValueStack arg0) {
		super(arg0);
	}

	private String value;

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public boolean start(Writer writer) {
		boolean result = super.start(writer);

		if (value == null) {
			value = "top";
		} else if (altSyntax()) {
			if (value.startsWith("%{") && value.endsWith("}")) {
				value = value.substring(2, value.length() - 1);
			}
		}
		int state = (Integer) this.getStack().findValue(value);
		try {
			if(state == 0){
				writer.write("预售中");
			}
			if(state == 1){
				writer.write("售票中");
			}
		} catch (IOException e) {
			logger.error(e);
		}
		return result;
	}
}
